package com.fenqing.leetcode.code.t0_200.t100_200;

import com.fenqing.annotations.Execute;
import com.fenqing.bean.TreeNode;
import com.fenqing.core.Topic;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fenqing
 */
public class Topic145 extends Topic {
    /**
     * 构造器
     *
     * @param input 输入
     */
    public Topic145(String input) {
        super(input);
    }

    @Execute
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        postorderTraversal(root, result);
        return result;
    }

    public void postorderTraversal(TreeNode root, List<Integer> result) {
        if (root == null) {
            return;
        }
        postorderTraversal(root.left, result);
        postorderTraversal(root.right, result);
        result.add(root.val);
    }

    public static void main(String[] args) {
        Topic145 topic145 = new Topic145("[1,null,2,3]");
        List<Integer> run = topic145.run();
        System.out.println(run);
    }
}
